#include "viewplayerstats.h"
#include "ui_viewplayerstats.h"

ViewPlayerStats::ViewPlayerStats(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ViewPlayerStats)
{
    ui->setupUi(this);
}
ViewPlayerStats::ViewPlayerStats(QVector<Player*> home, QVector<GameStatistic*> homeStats, QVector<Player*> away, QVector<GameStatistic*> awayStats):
    QWidget(0),
    ui(new Ui::ViewPlayerStats)
{
    ui->setupUi(this);
    homeLineup=home;
    homeStatistics=homeStats;
    awayLineup=away;
    awayStatistics=awayStats;
    isHomeSelected=true;
}

ViewPlayerStats::~ViewPlayerStats()
{
    delete ui;
}

void ViewPlayerStats::loadHome(){
    ui->nameComboBox->clear();
    isHomeSelected=true;
    for(int i=0;i<9;i++){
        Player *currentPlayer= homeLineup.at(i);
        QString name= currentPlayer->getLastName();
       // ui->nameComboBox->addItem(QString::number(currentPlayer->getJerseyNumber()));
        ui->nameComboBox->addItem(name);
    }
}

void ViewPlayerStats::loadAway(){
    ui->nameComboBox->clear();
    isHomeSelected=false;
    for(int i=0;i<9;i++){
        Player *currentPlayer= awayLineup.at(i);
        QString name= currentPlayer->getLastName();
       // ui->nameComboBox->addItem(QString::number(currentPlayer->getJerseyNumber()));
       ui->nameComboBox->addItem(name);
    }
}

void ViewPlayerStats::loadPlayer(){
    Player*currentPlayer;
    if(isHomeSelected){
        int index=ui->nameComboBox->currentIndex();
        currentPlayer=homeLineup.at(index);
        ui->atBatsLabel->setText(QString::number(homeStatistics.at(index)->getAtBats()));
        ui->hitsLabel->setText(QString::number(homeStatistics.at(index)->getHits()));
        ui->runsLabel->setText(QString::number(homeStatistics.at(index)->getRunsScored()));
        ui->rbiLabel->setText(QString::number(homeStatistics.at(index)->getRunsBattedIn()));
        ui->singlesLabel->setText(QString::number(homeStatistics.at(index)->getSingles()));
        ui->doubleLabel->setText(QString::number(homeStatistics.at(index)->getDoubles()));
        ui->triplesLabel->setText(QString::number(homeStatistics.at(index)->getTriples()));
        ui->homerunsLabel->setText(QString::number(homeStatistics.at(index)->getHomeRuns()));
        ui->grandSlamsLabel->setText(QString::number(homeStatistics.at(index)->getGrandSlams()));
        ui->walksLabel->setText(QString::number(homeStatistics.at(index)->getWalks()));
        ui->strikeoutsLabel->setText(QString::number(homeStatistics.at(index)->getStrikeouts()));
        ui->inningsPitchedLabel->setText(QString::number(homeStatistics.at(index)->getInningsPitched()));
        ui->walksPitchedLabel->setText(QString::number(homeStatistics.at(index)->getWalksPitched()));
        ui->strikeoutsPitchedLabel->setText(QString::number(homeStatistics.at(index)->getStrikeoutsPitched()));
        ui->hitsAllowedLabel->setText(QString::number(homeStatistics.at(index)->getHitsAllowed()));

    }
    else{
        int index=ui->nameComboBox->currentIndex();
        currentPlayer=awayLineup.at(index);
        ui->atBatsLabel->setText(QString::number(awayStatistics.at(index)->getAtBats()));
        ui->hitsLabel->setText(QString::number(awayStatistics.at(index)->getHits()));
        ui->runsLabel->setText(QString::number(awayStatistics.at(index)->getRunsScored()));
        ui->rbiLabel->setText(QString::number(awayStatistics.at(index)->getRunsBattedIn()));
        ui->singlesLabel->setText(QString::number(awayStatistics.at(index)->getSingles()));
        ui->doubleLabel->setText(QString::number(awayStatistics.at(index)->getDoubles()));
        ui->triplesLabel->setText(QString::number(awayStatistics.at(index)->getTriples()));
        ui->homerunsLabel->setText(QString::number(awayStatistics.at(index)->getHomeRuns()));
        ui->grandSlamsLabel->setText(QString::number(awayStatistics.at(index)->getGrandSlams()));
        ui->walksLabel->setText(QString::number(awayStatistics.at(index)->getWalks()));
        ui->strikeoutsLabel->setText(QString::number(awayStatistics.at(index)->getStrikeouts()));
        ui->inningsPitchedLabel->setText(QString::number(awayStatistics.at(index)->getInningsPitched()));
        ui->walksPitchedLabel->setText(QString::number(awayStatistics.at(index)->getWalksPitched()));
        ui->strikeoutsPitchedLabel->setText(QString::number(awayStatistics.at(index)->getStrikeoutsPitched()));
        ui->hitsAllowedLabel->setText(QString::number(awayStatistics.at(index)->getHitsAllowed()));
    }


}
